/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DataConverters.DataFormatters.formattersimpl;

import DataConverters.DataFormatters.AbstractDataFormatter;
import DataConverters.exceptions.DataConvertException;
import DataConverters.interfaces.IConvertable;
import DataConverters.interfaces.IConvertableFile;
import DataConverters.interfaces.dataformulaobject.intefaces.Cell;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.util.SortedSet;
import java.util.TreeSet;

/**
 *
 * @author Nobody
 */
public class GDAFormatter extends AbstractDataFormatter {

    public GDAFormatter(SortedSet<Cell> list) {
        super(list);
    }

    public GDAFormatter() {
        super(new TreeSet<Cell>());
    }

    @Override
    public void format(IConvertable source) throws DataConvertException {
        IConvertableFile fileSource = (IConvertableFile) source;

        try {
            OutputStream file = new FileOutputStream((fileSource.asFile()).getAbsoluteFile());
            OutputStream buffer = new BufferedOutputStream(file);
            ObjectOutput output = new ObjectOutputStream(buffer);
            try {
                output.writeObject(list);
            } finally {
                output.close();
            }
        } catch (IOException ex) {
            throw new DataConvertException(ex.getMessage(), ex);
        }

    }
}
